import dayjs from 'dayjs'
const objectSupport = require('dayjs/plugin/objectSupport')
dayjs.extend(objectSupport)

export default function (now, fmt) {
    return dayjs(new Date(now)).format(fmt)
}

// 只能选择今天以及今天以前的日期
export const disabledBeforeDate = (time, type) => {
    let currentDate = dayjs({ hour: 0, minute: 0, second: 0, milliseconde: 0, })
    if (type === 'dateTime') {
        currentDate = dayjs()
    }
    return dayjs(time).valueOf() > currentDate.valueOf()
}

// 只能选择今天以及今天以后的日期
export const disabledAfterDate = (time) => {
    const currentDate = dayjs({ hour: 0, minute: 0, second: 0, milliseconde: 0, })
    return dayjs(time).valueOf() < currentDate.valueOf()
}

// 睡眠
export const sleepSeconds = (seconds) => {
    return new Promise(resolve => {
        setTimeout(() => {
            return resolve()
        }, seconds)
    })
}
